<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::prefix('v1')
    ->namespace('Api')
    ->name('api.v1.')
    ->middleware('cors')
    ->group(function () {
        Route::middleware('throttle:' . config('api.rate_limits.access'))->group(function () {
            //后台相关路由
            Route::group(['domain' => '', 'namespace'=>'Admin', 'prefix'=> 'admin', 'middleware' => ['admin.guard']], function(){
                // 图片验证码
                Route::group(['prefix'=> 'captchas'], function(){
                    Route::any('store', 'CaptchasController@store')->name('captcha.store');
                    Route::any('verifyTip', 'CaptchasController@verifyTip')->name('captcha.verifyTip');
                    Route::any('verify', 'CaptchasController@verify')->name('captcha.verify');
                    Route::get('show', 'CaptchasController@show')->name('captcha.show');
                });
                // 登录
                Route::group(['prefix'=>'auth', 'middleware' => 'throttle:' . config('api.rate_limits.sign')], function(){
                    Route::post('store','AdminAuthController@store')->name('users.store');
                    Route::post('login','AdminAuthController@login')->name('users.login');
                    Route::get('logout', 'AdminAuthController@logout')->name('users.logout');

                });
                // 用户信息操作
                Route::group(['prefix'=>'users', 'middleware' => ['api.refresh']], function(){
                    //Route::get('show/{user}','AdminUserController@show')->name('users.show');
                    Route::get('info','AdminUserController@info')->name('users.info');
                    Route::post('update','AdminUserController@update')->name('users.update');
                    Route::post('resetPsd','AdminUserController@resetPsd')->name('users.resetPsd');

                });
                //用户后台操作
                Route::group(['prefix'=>'manage', 'middleware' => ['api.refresh', 'admin.power']], function(){
                    Route::group(['prefix' => 'routes'], function (){
                        Route::get('routes','RouteManageController@routes')->name('manage.routes.routes');
                        Route::post('addRoutes','RouteManageController@addRoutes')->name('manage.routes.addRoutes');
                        Route::post('update','RouteManageController@update')->name('manage.routes.update');
                        Route::get('index','RouteManageController@index')->name('manage.routes.index');
                        Route::get('getRoute','RouteManageController@getRoute')->name('manage.routes.getRoute');
                        Route::get('delete','RouteManageController@delete')->name('manage.routes.delete');
                        Route::post('setRole','RouteManageController@setRole')->name('manage.routes.setRole');
                    });
                    Route::group(['prefix' => 'powers'], function (){
                        Route::get('powers','PowerManageController@powers')->name('manage.powers.powers');
                        Route::get('getPower','PowerManageController@getPower')->name('manage.powers.getPower');
                        Route::get('index','PowerManageController@index')->name('manage.powers.index');
                        Route::get('refresh','PowerManageController@refresh')->name('manage.powers.refresh');
                        Route::get('delete','PowerManageController@delete')->name('manage.powers.delete');
                        Route::post('update','PowerManageController@update')->name('manage.powers.update');
                        Route::post('add','PowerManageController@add')->name('manage.powers.add');
                        Route::post('setRole','PowerManageController@setRole')->name('manage.powers.setRole');
                        Route::post('setRoute','PowerManageController@setRoute')->name('manage.powers.setRoute');
                    });
                    Route::group(['prefix' => 'roles'], function (){
                        Route::get('roles','RoleManageController@roles')->name('manage.roles.roles');
                        Route::get('index','RoleManageController@index')->name('manage.roles.index');
                        Route::post('add','RoleManageController@add')->name('manage.roles.add');
                        Route::post('update','RoleManageController@update')->name('manage.roles.update');
                    });

                    Route::group(['prefix' => 'adminUsers'], function (){
                        Route::get('getUser','AdminUserManageController@getUser')->name('manage.adminUsers.getUser');
                        Route::get('index','AdminUserManageController@index')->name('manage.adminUsers.index');
                        Route::post('setStatus','AdminUserManageController@setStatus')->name('manage.adminUsers.setStatus');
                        Route::post('setIpType','AdminUserManageController@setIpType')->name('manage.adminUsers.setIpType');
                        Route::post('resetPw','AdminUserManageController@resetPw')->name('manage.adminUsers.resetPw');
                        Route::post('setRole','AdminUserManageController@setRole')->name('manage.adminUsers.setRole');
                    });





                });
            });

            //对外相关路由
            Route::group(['domain' => '', 'middleware' => ['api.guard']], function (){
                Route::group(['prefix'=>'auth', 'middleware' => 'throttle:' . config('api.rate_limits.sign')], function(){
                    Route::post('store','AuthController@store')->name('user.store');
                    Route::post('login','AuthController@login')->name('user.login');
                    Route::get('logout', 'AuthController@logout')->name('user.logout');

                });

                Route::group(['prefix'=>'users', 'middleware' => ['api.refresh']], function(){
                    Route::get('index','UserController@index')->name('user.index');
                    Route::get('show/{user}','UserController@show')->name('user.show');
                    Route::get('info','UserController@info')->name('user.info');

                });
            });

        });
    });
